package a66weding.com.jiehuntong.activity.me;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.application.DataWareHourse;
import a66weding.com.jiehuntong.application.GlobalApplication;
import a66weding.com.jiehuntong.common.utils.CUtils;

/**
 * 这是我的-设置-修改手机号-修改绑定手机号的界面
 * Created by Administrator on 2016/7/14.
 */
public class MeAlterBindPhoneActivity extends MeBaseActivity implements View.OnClickListener{
    private LinearLayout mBackLay;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private Button mNestBtn;
    private RelativeLayout mHeaderRightRlay;
    private EditText mNowPhoneEt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_alter_bind_phone);
        ((GlobalApplication)getApplication()).getActivityManager().addActivity("MeAlterBindPhoneActivity",this);//全局的Activity的管理类
        ((GlobalApplication)getApplication()).getMeActivityManager().addActivity("MeAlterBindPhoneActivity",this);//获取到我的Acivity管理类,向里添加
        initview();
    }

    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.llay_header_back);
        mBackContentTv = (TextView) findViewById(R.id.tv_header_backcontent);
        mHeaderTitleTv = (TextView) findViewById(R.id.tv_header_title);
        mHeaderRightRlay = (RelativeLayout) findViewById(R.id.rlay_header_rightfunc);
        mNestBtn = (Button) findViewById(R.id.btn_me_next);
        mNowPhoneEt = (EditText) findViewById(R.id.et_phoneNum);

        mBackContentTv.setText("返回");
        mHeaderTitleTv.setText("修改绑定号码");
        mHeaderRightRlay.setVisibility(View.GONE);

        mBackLay.setOnClickListener(this);
        mNestBtn.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.llay_header_back:
                finish();
                break;
            case R.id.btn_me_next:
                String nowPhone = mNowPhoneEt.getText().toString().trim();
                String phoneNumber = DataWareHourse.getInstance().getmUser().getData().get(0).getNvc_MobilePhone();
                if(TextUtils.isEmpty(nowPhone)) {
                    CUtils.showToast("手机号不能为空");
                    return;
                } else if(nowPhone.length() != 11) {
                    CUtils.showToast("手机号码为11位");
                    return;
                } else if(!(nowPhone.equals(phoneNumber))) {
                    CUtils.showToast("您输入的手机号有误,请重新输入");
                    return;
                }
                intent.setClass(MeAlterBindPhoneActivity.this,MeSetBindnumActivity.class);
                startActivity(intent);
                break;

        }
    }

}
